package com.company;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 随机排序，直到排出有序结果
 * @date : 2023-04-28 下午1:48
 */

public class P053_MonkeySort {

    public static void main(String[] args) {
        int[] arr = new int[]{6, 4, 3, 5, 9, 0, 8, 1, 7, 2};
        List<Integer> list = new ArrayList<>();
        for (int num : arr) {
            list.add(num);
        }
        int count = 0;
        while (!isOrder(list)) {
            Collections.shuffle(list);
            count++;
        }
        System.out.println(count);
        System.out.println(list);
    }

    public static boolean isOrder(List<Integer> list) {
        if (list.size() == 1) {
            return true;
        }
        int num = list.get(0);
        for (Integer integer : list) {
            if (integer < num) {
                return false;
            }
            num = integer;
        }
        return true;
    }


}
